package com.sali.b_design_pattern.g_singleton_pattern.lesson_destroy_singleton.b_serialize;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * @description:
 * @date: 2023/3/19 19:03.
 * @version: 1.0
 */
public class Test1 {

    public static void main(String[] args) throws Exception {
        HungrySingleton singleton1 = null;
        HungrySingleton singleton2 = HungrySingleton.getInstance();

        FileOutputStream fos = new FileOutputStream("HungrySingleton.obj");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(singleton2);
        oos.flush();
        oos.close();
        FileInputStream fis = new FileInputStream("HungrySingleton.obj");
        ObjectInputStream ois = new ObjectInputStream(fis);
        singleton1 = (HungrySingleton) ois.readObject();
        ois.close();
        System.out.println(singleton1);
        System.out.println(singleton2);
    }

}
